/*-------------------------------------------------------------------------

***************** Modification History ***********************************
   @doc
   @module Transact.h - Header file for Transaction functionality |
   @end

$Log: /SoftPay/SPK2SIM/Source/Include/transact.h $

**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/

#ifndef VSTRAN_H
#define VSTRAN_H
#define INTRAN_H

#include <dbmgr.h>
#include <batch.h>
#include <check.h>
#include <trt.h>

typedef struct
{
	TRT_REC		srTRTRec;

    long lnSpecialMessageIndex;
    long lnOTInvNum;                                    /* Orig. Open Tab's Invoice No  */
    long lnOTAcctNum;									/* Orig. Open Tab's Acct No. */
    long lnECRInvNum;                                   /* Store's Invoice No  */
    short  inOperationCode;                               /* operation code   */
    short  inTransactionCode;                             /* transaction code   */
    char szOrigTransDate[ORIG_TRANS_DATE_SIZE + 1];     /* Original Trans Date for Debit Refund Trans */
    char szRespMsg[RESP_MSG_SIZE + 1];                  /* Response Message  */
    char szPIN[PIN_SIZE + 1];                           /* Pin data            */
    char szKSN[KSN_SIZE + 1];                           /* Authentication Key  */
    long lnMIStartTransTimer;                           // Transaction Timer
#ifdef PP501_ICPA
	char szPINKey[PIN_SIZE + 1];                  /* Communications Key  */
	char stSupPIN[PIN_SIZE + 1];                  /* Supervisor PIN      */
	char stMAC[MAC_SIZE + 1];                     /* MAC Code            */
	char stFldEncKey[KEY_SIZE + 1];               /* Field Encrypt Key   */
	char stPINPadSerNum[ICPA_SN_SIZE + 1];	      /* PP Serial Num       */
	char szBalance[KEY_SIZE + 1];                 /* Encrypted Balance   */
	char szDwnldKey[DWNLD_KEY_SIZE + 1];             /* DownLoad Key        */
#endif
    char szBatchNum[BATCH_NUM_SIZE + 1];                /* Batch Number        */
    char szSettDate[DATE_SIZE + 1];                     /* in MMDDYY format    */
    char szSettTime[TIME_SIZE + 1];                     /* in HHMMSS format    */
    char szZipCode[ZIPCODE_SIZE + 1];                   /* pj1 - Card holder zip code */
    char szAddress[ADDRESS_SIZE + 1];                   /* pj1 - Card holder address  */
    char szCVV2Value[CVV2_SIZE + 1];                    /* CVV2 value */
    char chCVV2PresenceIndicator;                       /* CVV2 presence indicator */
    long lnOldTaxAmount;                                /* Orig. tax amount for percent re-calculation */
    short  inChipStatus;				/* 0 NOT_USING_CHIP, 1 EMV_CARD, 2 EMV_EASY_ENTRY_CARD*/
#ifdef EMV_MODULE    
	short  inOnlineFailed;		// Did comms fail?
	short  inEMVCardDecision;		// Decision made by EMV card at First Generate AC: go online, 
								// authorise offline, decline offline.
	short  inEMVTermDecision;		// Decision made by terminal about EMV transaction 
								// - force online, force decline, no recommendation.
	short  inIssuerMVTIndex;	// Pointer to record with any EMV config. data mandated by issuer.
	short  inAcquirerMVTIndex;// Pointer to record with any EMV config. data mandated by acquirer.
#endif
#ifdef VXEMVAPP
	int  inOnlineFailed;		// Did comms fail?
	int  inEMVCardDecision;		// Decision made by EMV card at First Generate AC: go online, 
								// authorise offline, decline offline.
	int  inEMVTermDecision;		// Decision made by terminal about EMV transaction 
								// - force online, force decline, no recommendation.
	int  inIssuerMVTIndex;	// Pointer to record with any EMV config. data mandated by issuer.
	int  inAcquirerMVTIndex;// Pointer to record with any EMV config. data mandated by acquirer.
	int inFallbackAllowed;
#endif

    char szServiceCode[SVC_CODE_SIZE + 1];        /* Service code from track */
    char stT3Data[TRACK3_SIZE +1];                /* Track 3 bare format */
    short  inSaveTCTLanguage;                       /* Save language for hand held language swap*/

    unsigned char *pchFlexiData;				  		/* Pointer to Flexible transaction data */

    unsigned fReferral:1;                               /* Denotes that this trans is a referral */
    unsigned fSwitchedCard:1;
	unsigned fPreprinted:1;
	unsigned fPredialed:1;
	unsigned fReqMem:1;
	unsigned fBatchOpen:1;
	unsigned fOTBatchOpen:1;
    unsigned fAdjust:1;                                 /* Adjust */
    unsigned fTipAdjust:1;                              /* Tip Adjust */
    unsigned fTaxAdjust:1;                              /* Tax Adjust */
    unsigned fOtherAdjust:1;                            /* Other Adjust (i.e. User or Approval Code) */
    unsigned fAutoSettle:1;                             /* Settle started from Idle Loop on timer  */
    unsigned fFloorLimit:1;                             /* Trans is offline because of floor limit */
    unsigned fSendDuplicate:1;                          /* Sending duplicate transaction data flag */
    unsigned fVoidedBatchRec:1;                         /* VoidBatchRec has been run on current batch record */
    unsigned fAdjustedBatchRec:1;                       /* AdjustBatchRec has been run on current batch record */

    unsigned fLanguageOnSwipe:1;                        /* Language indicator is in track II data */
    unsigned fInteracDebit:1;                           /* Card swipe determines interac debit card */
    unsigned fRetry:1;                                  /* Transaction is being retried */
    unsigned fCardPresent:1;                            /* Card Present 0=no 1=yes */
    unsigned fHHSwipeOnly:1;                            /* Swipe Only 0=no 1=yes */
    unsigned fHHNoTax:1;                                /* HH No Tax 0=no 1=yes */
    unsigned fSettleSucceeded:1;                        /* Settle succeed 0=no 1=yes */
    unsigned fCounterPayTip:1;                          /* Counter Pay Tipping 0=no 1=yes */


	BATCH_KEY	srBKey;
	BATCH_REC	srBRec;
	BATCH_SKEY  srBSKey;								/* ACT2000 DBFM Search Key structure */

    DB_FILE dbBatch;
    DB_FILE dbOTBatch;

	CHECK_DATA_REC srCheck;

} TRANSACTION_OBJECT;

typedef int (*PFI_TO)(TRANSACTION_OBJECT *);
typedef void (*PVD_TO)(TRANSACTION_OBJECT *);
typedef int (*PFI_TO_PSZ_INT)(TRANSACTION_OBJECT *, char *, int);
typedef int (*PFI_TO_PSZ)(TRANSACTION_OBJECT *, char *);
typedef int (*PFI_TO_PSZ_F)(TRANSACTION_OBJECT *, char *, VS_BOOL);
typedef int (*PFI_TO_PFI_PIN)(TRANSACTION_OBJECT *, PFI, int *);
typedef void (*PVD_TO_INT)(TRANSACTION_OBJECT *, int);

/* Access MACRO Definitions */
#define inGGCode()                              pobTran->srBRec.inCode
#define vdSGCode(inTRANCODE)                    pobTran->srBRec.inCode = inTRANCODE

#define vdGGRespMsg(pchRespMsg)                 strlcpy(pchRespMsg, pobTran->szRespMsg, RESP_MSG_SIZE)
#define vdSGRespMsg(pchRespMsg)                 strlcpy(pobTran->szRespMsg, pchRespMsg, RESP_MSG_SIZE)

#define inGGOpCode()                            pobTran->inOperationCode
#define vdSGOpCode(inOpCode)                    pobTran->inOperationCode = inOpCode

#define inGGCurCDTIndex()                       pobTran->srBRec.inCDTIndex
#define vdSGCurCDTIndex(inCurIndex)             pobTran->srBRec.inCDTIndex = inCurIndex

#define inGetHostHandle()                       pobTran->srBKey.inHDTIndex
#define vdSetHostHandle(inHostIndex)			pobTran->srBKey.inHDTIndex = inHostIndex

#define fGGAutoSettle()                         pobTran->fAutoSettle
#define vdSGAutoSettle(fAUTOSETTLE)             pobTran->fAutoSettle = fAUTOSETTLE

VS_BOOL fRefundTrans(TRANSACTION_OBJECT *pobTran);
VS_BOOL fPhoneTrans(TRANSACTION_OBJECT *pobTran);
int inInitTran (TRANSACTION_OBJECT *pobTran);
int inUpdateTermInvAndHostInv (TRANSACTION_OBJECT *pobTran);
int inTransactions (TRANSACTION_OBJECT *pobTran);
void vdSetShift (TRANSACTION_OBJECT *pobTran);
void vdSetTranError (long lnErrMsgID);
int inInitPrintOption(TRANSACTION_OBJECT *pobTran);
int inDemoFunction (TRANSACTION_OBJECT *pobTran);
int inDefaultDemoFunction (TRANSACTION_OBJECT *pobTran);
int inStoreTranFlexiData(TRANSACTION_OBJECT *pobTran, unsigned short uiFieldID, unsigned char * pchData, unsigned short shDataLength);
int inGetTranFlexiData(TRANSACTION_OBJECT *pobTran, unsigned int uiFieldID, unsigned char * pchData, unsigned short shMaxLength);
int TRANSACT_CODE_CHECK(char * a,char *b,short *  c,char * d,unsigned char * e);

#undef INTRAN_H

#endif

